/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sse554_project3;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
 *
 * @author Derrick.Baptiste
 */
public class GameCanvas extends JFrame {   
    
    private Image imageBufferBoardPanel = null;
    private Image imageBufferPlayer1Panel = null;
    private Image imageBufferPlayer2Panel = null;
    private Image imageBufferPlayerPanelHidden = null;
    private Cell[][] cell = new Cell[15][15];
    
    // Variables declaration - do not modify
    private javax.swing.JPanel boardPanel;
    private javax.swing.JPanel controlPanel;
    private javax.swing.JPanel controlPanelLeft;
    private javax.swing.JPanel controlPanelRight;
    private javax.swing.JTextField jTextFieldLettersRemaining;
    private javax.swing.JTextField jTextFieldOutputNotifications;
    private javax.swing.JTextField jTextFieldPlayer1Score;
    private javax.swing.JTextField jTextFieldPlayer2Score;
    private javax.swing.JLabel lettersRemaining;
    private javax.swing.JButton passButton;
    private javax.swing.JLabel player1Score;
    private javax.swing.JLabel player2Score;
    private javax.swing.JPanel playerPanel;
    private javax.swing.JButton playerReadyButton;
    private javax.swing.JButton recallButton;
    private javax.swing.JButton submitButton;
    private javax.swing.JButton swapTilesButton;
    // End of variables declaration

    public GameCanvas(){
        initComponents();
        drawBoardPanelGraphics();
        drawPlayerPanelGraphics();
    }
    
    private void initComponents(){

        boardPanel = new javax.swing.JPanel();
        controlPanel = new javax.swing.JPanel();
        controlPanelRight = new javax.swing.JPanel();
        passButton = new javax.swing.JButton();
        recallButton = new javax.swing.JButton();
        swapTilesButton = new javax.swing.JButton();
        submitButton = new javax.swing.JButton();
        jTextFieldOutputNotifications = new javax.swing.JTextField();
        playerReadyButton = new javax.swing.JButton();
        controlPanelLeft = new javax.swing.JPanel();
        lettersRemaining = new javax.swing.JLabel();
        jTextFieldLettersRemaining = new javax.swing.JTextField();
        playerPanel = new javax.swing.JPanel();
        player1Score = new javax.swing.JLabel();
        jTextFieldPlayer1Score = new javax.swing.JTextField();
        player2Score = new javax.swing.JLabel();
        jTextFieldPlayer2Score = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setPreferredSize(new java.awt.Dimension(791, 955));

        boardPanel.setBackground(new java.awt.Color(100, 100, 100));
        boardPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                boardPanelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                boardPanelMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                boardPanelMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                boardPanelMouseReleased(evt);
            }
        });
        boardPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                boardPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout boardPanelLayout = new javax.swing.GroupLayout(boardPanel);
        boardPanel.setLayout(boardPanelLayout);
        boardPanelLayout.setHorizontalGroup(
            boardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        boardPanelLayout.setVerticalGroup(
            boardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 750, Short.MAX_VALUE)
        );

        controlPanel.setBackground(new java.awt.Color(0, 0, 0));
        controlPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
        controlPanel.setPreferredSize(new java.awt.Dimension(750, 199));

        controlPanelRight.setBackground(new java.awt.Color(204, 204, 204));
        controlPanelRight.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));

        passButton.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        passButton.setText("Pass");
        passButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                passButtonMouseClicked(evt);
            }
        });

        recallButton.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        recallButton.setText("Recall");
        recallButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                recallButtonMouseClicked(evt);
            }
        });

        swapTilesButton.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        swapTilesButton.setText("Swap");
        swapTilesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                swapTilesButtonMouseClicked(evt);
            }
        });

        submitButton.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        submitButton.setText("Submit");
        submitButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                submitButtonMouseClicked(evt);
            }
        });

        jTextFieldOutputNotifications.setBackground(new java.awt.Color(153, 255, 204));
        jTextFieldOutputNotifications.setEditable(false);
        jTextFieldOutputNotifications.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        jTextFieldOutputNotifications.setText("Output Notifications to User");

        playerReadyButton.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        playerReadyButton.setText("Player X Ready?");
        playerReadyButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                playerReadyButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout controlPanelRightLayout = new javax.swing.GroupLayout(controlPanelRight);
        controlPanelRight.setLayout(controlPanelRightLayout);
        controlPanelRightLayout.setHorizontalGroup(
            controlPanelRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelRightLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlPanelRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(playerReadyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(controlPanelRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jTextFieldOutputNotifications)
                        .addGroup(controlPanelRightLayout.createSequentialGroup()
                            .addComponent(passButton, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(recallButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(swapTilesButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(submitButton))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        controlPanelRightLayout.setVerticalGroup(
            controlPanelRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelRightLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlPanelRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passButton)
                    .addComponent(recallButton)
                    .addComponent(swapTilesButton)
                    .addComponent(submitButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldOutputNotifications, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(playerReadyButton)
                .addContainerGap())
        );

        controlPanelLeft.setBackground(new java.awt.Color(204, 204, 204));
        controlPanelLeft.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));

        lettersRemaining.setFont(new java.awt.Font("Pristina", 1, 18)); // NOI18N
        lettersRemaining.setText("Letters Remaining:");

        jTextFieldLettersRemaining.setBackground(new java.awt.Color(153, 255, 204));
        jTextFieldLettersRemaining.setEditable(false);
        jTextFieldLettersRemaining.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        jTextFieldLettersRemaining.setText("Empty");

        playerPanel.setBackground(new java.awt.Color(204, 204, 255));
        playerPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        playerPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        playerPanel.setPreferredSize(new java.awt.Dimension(350, 50));
        playerPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playerPanelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                playerPanelMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                playerPanelMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                playerPanelMouseReleased(evt);
            }
        });
        playerPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                playerPanelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout playerPanelLayout = new javax.swing.GroupLayout(playerPanel);
        playerPanel.setLayout(playerPanelLayout);
        playerPanelLayout.setHorizontalGroup(
            playerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 352, Short.MAX_VALUE)
        );
        playerPanelLayout.setVerticalGroup(
            playerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 48, Short.MAX_VALUE)
        );

        player1Score.setFont(new java.awt.Font("Pristina", 1, 18)); // NOI18N
        player1Score.setText("Player 1 Score:");

        jTextFieldPlayer1Score.setBackground(new java.awt.Color(153, 255, 204));
        jTextFieldPlayer1Score.setEditable(false);
        jTextFieldPlayer1Score.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        jTextFieldPlayer1Score.setText("0");

        player2Score.setFont(new java.awt.Font("Pristina", 1, 18)); // NOI18N
        player2Score.setText("Player 2 Score:");

        jTextFieldPlayer2Score.setBackground(new java.awt.Color(153, 255, 204));
        jTextFieldPlayer2Score.setEditable(false);
        jTextFieldPlayer2Score.setFont(new java.awt.Font("Pristina", 1, 16)); // NOI18N
        jTextFieldPlayer2Score.setText("0");

        javax.swing.GroupLayout controlPanelLeftLayout = new javax.swing.GroupLayout(controlPanelLeft);
        controlPanelLeft.setLayout(controlPanelLeftLayout);
        controlPanelLeftLayout.setHorizontalGroup(
            controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLeftLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(controlPanelLeftLayout.createSequentialGroup()
                        .addComponent(lettersRemaining)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldLettersRemaining, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, controlPanelLeftLayout.createSequentialGroup()
                            .addComponent(player1Score)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldPlayer1Score, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(player2Score)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldPlayer2Score, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(playerPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        controlPanelLeftLayout.setVerticalGroup(
            controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLeftLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lettersRemaining)
                    .addComponent(jTextFieldLettersRemaining, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(playerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlPanelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(player1Score)
                    .addComponent(jTextFieldPlayer1Score, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(player2Score)
                    .addComponent(jTextFieldPlayer2Score, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(64, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLayout.createSequentialGroup()
                .addComponent(controlPanelLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(controlPanelRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(controlPanelRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(controlPanelLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(boardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 734, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(boardPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
        
        //panelPaddingWidth and panelPaddingHeight must be called after pack()
        //to yeild non-zero values.  The padding values are used to set the size
        //of the JFrame so that the boardPanel within the JFrame is perfectly square.
        int panelPaddingWidth = this.getWidth() - boardPanel.getWidth();
        int panelPaddingHeight = this.getHeight() - boardPanel.getHeight();
   
  System.out.println("panelPaddingWidth = " + panelPaddingWidth);
  System.out.println("panelPaddingHeight = " + panelPaddingHeight);

        setSize(750 + panelPaddingWidth, 750 + panelPaddingHeight);
   
  System.out.println("this.getWidth() = " + this.getWidth());
  System.out.println("this.getHeight() = " + this.getHeight());

        //panelPaddingWidth and panelPaddingHeight must be called after pack()
        //to yeild non-zero values.  The padding values are used to set the size
        //of the JFrame so that the boardPanel within the JFrame is perfectly square.
//        int panelPaddingWidth = this.getWidth() - boardPanel.getWidth();
//        int panelPaddingHeight = this.getHeight() - boardPanel.getHeight();
        
//System.out.println("panelPaddingWidth = " + panelPaddingWidth);
//System.out.println("panelPaddingHeight = " + panelPaddingHeight);
//System.out.println("getWidth() = " + getWidth());
//System.out.println("getHeight() = " + getHeight());
//System.out.println("boardPanel.getWidth() = " + boardPanel.getWidth());
//System.out.println("boardPanel.getHeight() = " + boardPanel.getHeight());       
        
        setTitle("Scrabble");
        setVisible(true);
     
        //Must be called after setVisible(true) for correct window dimensions
        //setResizable(false);
    }
    
    private void playerPanelMouseEntered(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void playerPanelMousePressed(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void playerPanelMouseExited(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void playerPanelMouseReleased(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void playerPanelMouseDragged(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void passButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void recallButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void swapTilesButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void submitButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void playerReadyButtonMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void boardPanelMouseEntered(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void boardPanelMouseExited(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void boardPanelMousePressed(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void boardPanelMouseReleased(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void boardPanelMouseDragged(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }
    
    private void drawBoardPanelGraphics(){
        
        int boardWidth = boardPanel.getWidth();
        int boardHeight = boardPanel.getHeight();
        
System.out.println("boardPanel.getWidth() = " + boardWidth);
System.out.println("boardPanel.getHeight() = " + boardHeight);
System.out.println("controlPanel.getWidth() = " + controlPanel.getWidth());
System.out.println("controlPanel.getHeight() = " + controlPanel.getHeight());
System.out.println("playerPanel.getWidth() = " + playerPanel.getWidth());
System.out.println("playerPanel.getHeight() = " + playerPanel.getHeight());

        //Get boardPanel image to enable drawing to offscreen image
        imageBufferBoardPanel = boardPanel.createImage(boardWidth, boardHeight);
        Graphics g = imageBufferBoardPanel.getGraphics();
        
        //Set boardPanel background color
        g.setColor(new Color(153,255,204));
        g.fillRect(0,0,boardWidth,boardHeight);
        
        //Set grid line color
        g.setColor(Color.BLACK);
        
        //Draw grid lines.
        for(int x = 0; x <= boardWidth; x+=50){
            g.drawLine(x, 0, x, boardHeight);
            
        }
        g.drawLine(boardHeight-1,0,boardHeight-1,boardHeight-1);
        for(int y = 0; y <= boardHeight; y+=50){
            g.drawLine(0, y, boardWidth, y);
        }
        g.drawLine(0,boardWidth-1,boardWidth-1,boardWidth-1);
        
        
        //Get and store upper left coordinates of each cell in grid.
      /*  int count = 0;
        System.out.println("cell.length = " + cell.length);
        System.out.println("cell[0].length = " + cell[0].length);*/
        for(int x = 0; x < cell.length; x++)
        {
            for(int y = 0; y < cell[0].length; y++)
            {
                cell[x][y] = new Cell();
                cell[x][y].setPoint(new Point(x*50, y*50));
                cell[x][y].setCellType(CellType.NULL);
               // g.fillOval(x*50,y*50,10,10);
               // count++;
            }
        }
        
        //System.out.println("count = " + count);
       
            //Print out the 
            /*for(int i = 0; i < cell.length; i++)
                for(int j = 0; j < cell[0].length; j++){
                    System.out.println("cell[" + i  + "]" + "[" + j + "] = " + cell[i][j].getPoint());
                }*/
            
        //Draw special cells to boardPanel
        try{
            drawSpecialCells();
        } catch (IOException ex) {
            Logger.getLogger(GameCanvas.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    private void drawSpecialCells() throws IOException{
        
        Image cellImage;
        Graphics cg;
        
        //Draw start cell
        File file = new File(".\\src\\images\\start.gif");
        cellImage = ImageIO.read(file);
        cg = imageBufferBoardPanel.getGraphics();
        cg.drawImage(cellImage,351,351,null);
        
        //Draw DL cells
        file = new File(".\\src\\images\\DL.gif");
        cellImage = ImageIO.read(file);
        cg.drawImage(cellImage,151,1,null);
        cg.drawImage(cellImage,551,1,null);
        cg.drawImage(cellImage,301,101,null);
        cg.drawImage(cellImage,401,101,null);
        cg.drawImage(cellImage,1,151,null);
        cg.drawImage(cellImage,351,151,null);
        cg.drawImage(cellImage,701,151,null);
        cg.drawImage(cellImage,101,301,null);
        cg.drawImage(cellImage,301,301,null);
        cg.drawImage(cellImage,401,301,null);
        cg.drawImage(cellImage,601,301,null);
        cg.drawImage(cellImage,151,351,null);
        cg.drawImage(cellImage,551,351,null);
        cg.drawImage(cellImage,101,401,null);
        cg.drawImage(cellImage,301,401,null);
        cg.drawImage(cellImage,401,401,null);
        cg.drawImage(cellImage,601,401,null);
        cg.drawImage(cellImage,1,551,null);
        cg.drawImage(cellImage,351,551,null);
        cg.drawImage(cellImage,701,551,null);
        cg.drawImage(cellImage,301,601,null);
        cg.drawImage(cellImage,401,601,null);
        cg.drawImage(cellImage,151,701,null);
        cg.drawImage(cellImage,551,701,null);
        
        //Draw DW cells
        file = new File(".\\src\\images\\DW.gif");
        cellImage = ImageIO.read(file);
        cg.drawImage(cellImage,51,51,null);
        cg.drawImage(cellImage,101,101,null);
        cg.drawImage(cellImage,151,151,null);
        cg.drawImage(cellImage,201,201,null);
        cg.drawImage(cellImage,651,51,null);
        cg.drawImage(cellImage,601,101,null);
        cg.drawImage(cellImage,551,151,null);
        cg.drawImage(cellImage,501,201,null);
        cg.drawImage(cellImage,201,501,null);
        cg.drawImage(cellImage,151,551,null);
        cg.drawImage(cellImage,101,601,null);
        cg.drawImage(cellImage,51,651,null);
        cg.drawImage(cellImage,501,501,null);
        cg.drawImage(cellImage,551,551,null);
        cg.drawImage(cellImage,601,601,null);
        cg.drawImage(cellImage,651,651,null);
        
        //Draw TL cells
        file = new File(".\\src\\images\\TL.gif");
        cellImage = ImageIO.read(file);
        cg.drawImage(cellImage,251,51,null);
        cg.drawImage(cellImage,451,51,null);
        cg.drawImage(cellImage,51,251,null);
        cg.drawImage(cellImage,251,251,null);
        cg.drawImage(cellImage,451,251,null);
        cg.drawImage(cellImage,651,251,null);
        cg.drawImage(cellImage,51,451,null);
        cg.drawImage(cellImage,251,451,null);
        cg.drawImage(cellImage,451,451,null);
        cg.drawImage(cellImage,651,451,null);
        cg.drawImage(cellImage,251,651,null);
        cg.drawImage(cellImage,451,651,null);
        
        //Draw TW cells
        file = new File(".\\src\\images\\TW.gif");
        cellImage = ImageIO.read(file);
        cg.drawImage(cellImage,1,1,null);
        cg.drawImage(cellImage,351,1,null);
        cg.drawImage(cellImage,701,1,null);
        cg.drawImage(cellImage,1,351,null);
        cg.drawImage(cellImage,701,351,null);
        cg.drawImage(cellImage,1,701,null);
        cg.drawImage(cellImage,351,701,null);
        cg.drawImage(cellImage,701,701,null);
  
        /*
        //Test drawing transparent tile
        file = new File(".\\src\\images\\tile_image3.png");
        cellImage = ImageIO.read(file);
        cg.drawImage(cellImage,701,701,null);
        cg.drawImage(cellImage,51,51,null);
        cg.drawImage(cellImage,251,51,null);
         cg.drawImage(cellImage,401,101,null);*/
    }
    
    private void drawPlayerPanelGraphics(){
        
        Graphics g;
        File file = new File(".\\src\\images\\player_panel_hidden.gif");
        try {
            imageBufferPlayerPanelHidden = ImageIO.read(file);
            g = imageBufferPlayerPanelHidden.getGraphics();
            
        } catch (IOException ex) {
            Logger.getLogger(GameCanvas.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
        //System.out.println("GameCanvas paint method called.");
        if(imageBufferBoardPanel != null){
            Graphics g2 = boardPanel.getGraphics();
            g2.drawImage(imageBufferBoardPanel, 0, 0, null);
        }
        if(imageBufferPlayerPanelHidden != null){
            Graphics g3 = playerPanel.getGraphics();
            g3.drawImage(imageBufferPlayerPanelHidden, 0, 0, null);
        }
    }
    
    
    
    
}
